<template>
    <el-form :model="form" label-width="auto">
        <el-form-item label="房间号">
            <el-input v-model="form.room_no" readonly />
        </el-form-item>
        <el-form-item label="床号">
            <el-input v-model="form.bed_no" readonly />
        </el-form-item>
        <el-form-item label="床状态">
            <el-input v-model="form.bed_status" readonly />
        </el-form-item>
        <el-form-item label="备注">
            <el-input v-model="form.remarks" readonly />
        </el-form-item>
        <el-form-item label="创建人">
            <el-input v-model="form.create_by" readonly />
        </el-form-item>
        <el-form-item label="创建时间">
            <el-form-item>
                <el-date-picker v-model="form.create_time" type="date" aria-label="Pick a date"
                          placeholder="请选择日期" style="width: 100%" format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD" readonly/>
            </el-form-item>
        </el-form-item>
        <el-form-item label="更新人">
            <el-input v-model="form.update_by" readonly />
        </el-form-item>
        <el-form-item label="更新时间">
            <el-form-item>
                <el-date-picker v-model="form.update_time" type="date" aria-label="Pick a date"
                          placeholder="请选择日期" style="width: 100%"  format="YYYY-MM-DD"
                          value-format="YYYY-MM-DD" readonly/>
            </el-form-item>
        </el-form-item>
        <el-form-item>
            <el-button @click="cancel">关闭</el-button>
        </el-form-item>
    </el-form>
</template>

<script setup name='BedHistoryEdit'>
import { ref, onMounted } from 'vue';
import { ElNotification } from 'element-plus';
import { getHistoryById } from '@/api/bed/index';
import { defineProps } from 'vue';

const { closeDialog, editId } = defineProps(['closeDialog', 'editId']);

// 表单数据
const form = ref({
    room_no: '',
    bed_no: '',
    bed_status: '',
    remarks: '',
    create_by: '',
    create_time: '',
    update_by: '',
    update_time: ''
});

// 关闭对话框
const cancel = () => {
    closeDialog(false);
};

// 根据主键查询使用历史信息
const pageGetHistoryById = async () => {
    try {
        const history = await getHistoryById(editId);
        form.value = history;
    } catch (error) {
        ElNotification({
            title: '消息',
            type: 'error',
            message: '获取使用历史信息失败，请稍后重试'
        });
    }
};

onMounted(() => {
    // 如果有 editId，说明是查看详情，需要根据主键查询
    if (editId) {
        pageGetHistoryById();
    }
});
</script>

<style scoped></style>